package top.majuan.study.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "threeservlet", value = "/three.servlet")
public class ThreeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 编码设置
        // req.setCharacterEncoding("UTF-8");
        // resp.setCharacterEncoding("UTF-8");
        // 获取请求中的参数
        String name = req.getParameter("name");
        name = name == null ? "新玩家" : name;
        // 应答结果
        resp.setContentType("text/plain");
        PrintWriter out = resp.getWriter();
        out.println("欢迎" + name + "进入");
        out.close();

    }


}
